```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SpringBoot自动装配原理深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
            background-color: #f9fafb;
        }
        .hero {
            background: linear-gradient(135deg, #6b21a8 0%, #9333ea 100%);
            color: white;
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            overflow: hidden;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            background-color: rgba(139, 92, 246, 0.1);
            border-left: 4px solid #8b5cf6;
        }
        .custom-divider {
            height: 2px;
            background: linear-gradient(90deg, rgba(139, 92, 246, 0.1) 0%, #8b5cf6 50%, rgba(139, 92, 246, 0.1) 100%);
            margin: 2rem 0;
        }
        .concept-icon {
            width: 60px;
            height: 60px;
            background-color: #8b5cf6;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-6 md:px-16 lg:px-24">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">SpringBoot自动装配原理</h1>
                    <p class="text-xl opacity-90 mb-8">揭秘SpringBoot如何通过约定优于配置的哲学简化开发</p>
                    <div class="flex flex-wrap gap-4">
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">@SpringBootApplication</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">starter机制</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">spring.factories</span>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <img src="https://cdn.nlark.com/yuque/0/2024/jpeg/21449790/1706004354300-e3277211-f10e-42c0-8cbe-7ba22462b0d5.jpeg" alt="SpringBoot自动装配" class="rounded-xl shadow-2xl transform rotate-2 hover:rotate-0 transition-transform duration-500">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-6xl px-6 py-16">
        <!-- What is Auto-Configuration -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-magic text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">什么是自动装配</h2>
            </div>
            
            <div class="bg-white p-8 rounded-xl shadow-sm mb-8 card">
                <p class="text-gray-700 mb-6">在我们之前使用Spring进行开发的时候，需要通过XML配置文件来配置我们所需要的Bean对象到Spring容器中，例如：</p>
                
                <div class="code-block mb-6">
                    <pre class="p-5 overflow-x-auto"><code class="language-xml">&lt;bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"&gt;&lt;/bean&gt;
&lt;bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean"&gt;&lt;/bean&gt;
&lt;bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;&lt;/bean&gt;</code></pre>
                </div>
                
                <p class="text-gray-700 mb-6">但是这样并不方便：</p>
                <ul class="list-disc pl-6 mb-6 text-gray-700 space-y-2">
                    <li>配置XML文件复杂且麻烦</li>
                    <li>XML配置文件如果有错误，排查问题起来会比较慢</li>
                </ul>
                
                <p class="text-gray-700 mb-6">SpringBoot通过自动装配避免使用XML配置文件，只需要配置yml或者properties文件，就可以将我们所需要的Bean对象加载到Spring容器中。</p>
                
                <div class="highlight p-6 rounded-lg">
                    <p class="text-lg font-semibold text-purple-700">自动装配就是Spring自动帮你把所需要的Bean对象进行装配注入到Spring容器中。</p>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mt-10">
                <div class="bg-white p-8 rounded-xl shadow-sm card">
                    <div class="concept-icon mx-auto">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h3 class="text-xl font-bold text-center mb-4">自动装配的优势</h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>配置简单，避免使用大量XML方式进行配置</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>提高开发效率</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-sm card">
                    <div class="concept-icon mx-auto">
                        <i class="fas fa-puzzle-piece"></i>
                    </div>
                    <h3 class="text-xl font-bold text-center mb-4">Starter机制</h3>
                    <p class="text-gray-700 mb-4">以SpringBoot整合MyBatis为例：</p>
                    <div class="code-block mb-4">
                        <pre class="p-4 overflow-x-auto text-sm"><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt;
    &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;2.2.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
                    </div>
                    <p class="text-gray-700 text-sm">starter本身没有源码，只有一个pom文件，作用是帮我们引入其他jar包</p>
                </div>
            </div>
        </section>
        
        <!-- Auto-Configuration Mechanism -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-cogs text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">自动装配机制</h2>
            </div>
            
            <div class="bg-white p-8 rounded-xl shadow-sm mb-8 card">
                <p class="text-gray-700 mb-6">学习自动装配要从SpringBoot主启动类上的<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">@SpringBootApplication</code>注解开始。这是一个组合注解，可以看成<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">@Configuration</code>、<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">@EnableAutoConfiguration</code>、<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">@ComponentScan</code>注解的集合。</p>
                
                <div class="code-block mb-6">
                    <pre class="p-5 overflow-x-auto"><code class="language-java">@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration  // 配置类
@EnableAutoConfiguration  // 自动装配
@ComponentScan(           // 包扫描
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
}</code></pre>
                </div>
                
                <div class="grid md:grid-cols-3 gap-6 mt-8">
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 text-purple-700">@SpringBootConfiguration</h4>
                        <p class="text-gray-700">本质上是一个<code class="bg-gray-200 px-1 py-0.5 rounded text-purple-600">@Configuration</code>注解。启动类就是一个配置类，可以在其中完成一些配置。</p>
                    </div>
                    
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 text-purple-700">@ComponentScan</h4>
                        <p class="text-gray-700">包扫描注解，默认扫描启动类所在目录下的所有对象。</p>
                    </div>
                    
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 text-purple-700">@EnableAutoConfiguration</h4>
                        <p class="text-gray-700">开启自动配置，将Spring扫描到的Bean对象加载到容器中。</p>
                    </div>
                </div>
            </div>
            
            <div class="bg-white p-8 rounded-xl shadow-sm mb-8 card">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">自动装配流程</h3>
                
                <div class="mb-8">
                    <div class="flex items-start mb-6">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1 flex-shrink-0">1</div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2">获取自动配置类</h4>
                            <p class="text-gray-700">通过<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">AutoConfigurationImportSelector</code>获取需要自动装配的bean</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start mb-6">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1 flex-shrink-0">2</div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2">加载spring.factories</h4>
                            <p class="text-gray-700">在classpath下加载所有<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">META-INF/spring.factories</code>文件内容</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start mb-6">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1 flex-shrink-0">3</div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2">过滤配置类</h4>
                            <p class="text-gray-700">对配置类进行去重、排序，并移除需要排除的bean</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1 flex-shrink-0">4</div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2">实例化Bean</h4>
                            <p class="text-gray-700">返回需要被加载的类数组，Spring通过反射实例化这些bean并放入IOC容器</p>
                        </div>
                    </div>
                </div>
                
                <div class="code-block mb-6">
                    <pre class="p-5 overflow-x-auto"><code class="language-java">private static Map&lt;String, List&lt;String&gt;&gt; loadSpringFactories(ClassLoader classLoader) {
    // 加载所有starter依赖中的spring.factories文件
    Enumeration urls = classLoader.getResources("META-INF/spring.factories");
    // ...
}</code></pre>
                </div>
                
                <div class="grid md:grid-cols-2 gap-6 mt-8">
                    <div class="bg-purple-50 p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 text-purple-700">官方starter</h4>
                        <p class="text-gray-700">命名格式：<code class="bg-purple-100 px-2 py-1 rounded text-purple-600">spring-boot-starter-xxx</code></p>
                        <p class="text-gray-700 mt-2">例如：<code class="bg-purple-100 px-2 py-1 rounded text-purple-600">spring-boot-starter-web</code></p>
                    </div>
                    
                    <div class="bg-purple-50 p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 text-purple-700">第三方starter</h4>
                        <p class="text-gray-700">命名格式：<code class="bg-purple-100 px-2 py-1 rounded text-purple-600">xxx-spring-boot-starter</code></p>
                        <p class="text-gray-700 mt-2">例如：<code class="bg-purple-100 px-2 py-1 rounded text-purple-600">mybatis-spring-boot-starter</code></p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Custom Starter -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-hammer text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">自定义Starter</h2>
            </div>
            
            <div class="bg-white p-8 rounded-xl shadow-sm card">
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-2xl font-bold mb-6 text-gray-800">实现步骤</h3>
                        
                        <div class="space-y-6">
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 rounded-full w-6 h-6 flex items-center justify-center mr-4 mt-1 flex-shrink-0">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-1">1. 新建Maven工程</h4>
                                    <p class="text-gray-700 text-sm">创建标准的Maven项目结构</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 rounded-full w-6 h-6 flex items-center justify-center mr-4 mt-1 flex-shrink-0">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-1">2. 定义属性读取类</h4>
                                    <p class="text-gray-700 text-sm">使用<code class="bg-gray-100 px-1 py-0.5 rounded text-purple-600">@ConfigurationProperties</code>读取配置</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 rounded-full w-6 h-6 flex items-center justify-center mr-4 mt-1 flex-shrink-0">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-1">3. 定义自动装配类</h4>
                                    <p class="text-gray-700 text-sm">创建<code class="bg-gray-100 px-1 py-0.5 rounded text-purple-600">@Configuration</code>类并定义Bean</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 rounded-full w-6 h-6 flex items-center justify-center mr-4 mt-1 flex-shrink-0">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-1">4. 创建spring.factories</h4>
                                    <p class="text-gray-700 text-sm">在<code class="bg-gray-100 px-1 py-0.5 rounded text-purple-600">META-INF</code>下添加配置文件</p>
                                </div>
                            </div>
                            
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 rounded-full w-6 h-6 flex items-center justify-center mr-4 mt-1 flex-shrink-0">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-1">5. 引入并使用</h4>
                                    <p class="text-gray-700 text-sm">在其他项目中引入starter依赖并使用</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div>
                        <h3 class="text-2xl font-bold mb-6 text-gray-800">代码示例</h3>
                        
                        <div class="code-block mb-4">
                            <pre class="p-4 overflow-x-auto text-sm"><code class="language-java">// 属性读取类
@Data
@Component
@ConfigurationProperties(prefix = "mystarter")
public class MyStartProperties {
    private String name;
    private Integer age;
    private String sex;
}

// 自动装配类
public class MyStarterAutoConfiguration {
    @Bean
    public Map&lt;String, String&gt; demoMap() {
        Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
        map.put("test", "myStarter");
        return map;
    }
}</code></pre>
                        </div>
                        
                        <div class="code-block">
                            <pre class="p-4 overflow-x-auto text-sm"><code class="language-properties"># spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.ts.boot.MyStarterAutoConfiguration</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Summary -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-star text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">总结</h2>
            </div>
            
            <div class="bg-white p-8 rounded-xl shadow-sm card">
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-2xl font-bold mb-6 text-gray-800">核心要点</h3>
                        
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                                <span>SpringBoot自动装配通过约定优于配置的哲学简化开发</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                                <span>starter机制通过依赖传递自动引入所需jar包</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                                <span>autoconfigure模块完成实际的自动装配逻辑</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                                <span>项目启动时通过SpringFactoriesLoader加载spring.factories配置</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                                <span>经过过滤和移除后确定需要装载的类，交给Spring容器装配</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div>
                        <h3 class="text-2xl font-bold mb-6 text-gray-800">自动装配流程</h3>
                        
                        <div class="bg-gradient-to-br from-purple-50 to-blue-50 p-6 rounded-lg h-full">
                            <div class="flex flex-col space-y-4">
                                <div class="flex items-center">
                                    <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4">1</div>
                                    <div>
                                        <p class="font-medium">@SpringBootApplication</p>
                                        <p class="text-sm text-gray-600">启动自动装配流程</p>
                                    </div>
                                </div>
                                
                                <div class="flex items-center">
                                    <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4">2</div>
                                    <div>
                                        <p class="font-medium">加载spring.factories</p>
                                        <p class="text-sm text-gray-600">获取所有自动配置类</p>
                                    </div>
                                </div>
                                
                                <div class="flex items-center">
                                    <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4">3</div>
                                    <div>
                                        <p class="font-medium">过滤配置类</p>
                                        <p class="text-sm text-gray-600">条件化加载实际可用的配置</p>
                                    </div>
                                </div>
                                
                                <div class="flex items-center">
                                    <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-4">4</div>
                                    <div>
                                        <p class="font-medium">实例化Bean</p>
                                        <p class="text-sm text-gray-600">通过反射创建Bean实例</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```